package com.qianfeng.app;

import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
@SpringBootApplication(scanBasePackages="com.qianfeng.controller")
/*public class SpringApplicarions extends WebMvcConfigurerAdapter{ //使用FastJson解析数据方式一：extends WebMvcConfigurerAdapter
	
	
	
	@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
		//创建FastJson的消息转换器
		FastJsonHttpMessageConverter convert = new FastJsonHttpMessageConverter();
		//创建FastJson的配置对象
		FastJsonConfig config= new FastJsonConfig();
		//对Json数据进行格式化
		config.setSerializerFeatures(SerializerFeature.PrettyFormat);
		
		convert.setFastJsonConfig(config);
		converters.add(convert);
		
		
	}

	public static void main(String[] args) {
		SpringApplication.run(SpringApplicarions.class, args);
	}
}*/

public class SpringApplicarions {
	
	@Bean //使用FastJson解析数据方式二：将FastJson注入到Spring容器中
	public HttpMessageConverters fastJsonMessageConverter() {
		//创建FastJson的消息转换器
		FastJsonHttpMessageConverter convert = new FastJsonHttpMessageConverter();
		//创建FastJson的配置对象
		FastJsonConfig config= new FastJsonConfig();
		//对Json数据进行格式化
		config.setSerializerFeatures(SerializerFeature.PrettyFormat);
		
		convert.setFastJsonConfig(config);
	    HttpMessageConverter<?> con=convert;
	    return new HttpMessageConverters(con);
		
		
	}

	public static void main(String[] args) {
		SpringApplication.run(SpringApplicarions.class, args);
	}
}

